package org.xlx.xlx_oa.common;

import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.xlx.xlx_oa.role_user.domain.AdmUser;
import org.xlx.xlx_oa.utils.StringRedisUtil;

/**
 * <p>
 * 验证缓存
 * </p>
 *
 * @author yuszou
 * @since 2022/1/30 14:21
 */
@Component
public class AuthCache {
    @Autowired
    private StringRedisUtil stringRedisUtil;

    public void setSessionData(String key, String value) {
        stringRedisUtil.set(key, value);
    }

    public AdmUser getSessionData(String key) {
        String value = stringRedisUtil.get(key);
        return (!StringUtils.hasText(value)) ? null : JSON.parseObject(value, AdmUser.class);
    }

    public boolean deleteSessionData(String key) {
        return stringRedisUtil.delete(key);
    }

    public void expireSessionData(String key) {
        stringRedisUtil.expire(key, Constant.EXPIRE_TIME);
    }
}
